<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Git版本控制 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/68.868cd00b.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/13.0a6ebfcf.js"><link rel="prefetch" href="/assets/js/14.03fc6f12.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/22.55c868be.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/28.b383a871.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/65.6afc33db.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础语法</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>常用类</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础高级</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>脚手架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>技术增值</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/9e54ff/" class="sidebar-link">Activiti7工作流讲义</a></li><li><a href="/pages/ca48f7/" aria-current="page" class="active sidebar-link">Git版本控制</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_2-1-团队开发问题" class="sidebar-link">2.1 团队开发问题</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_2-2-版本控制思想" class="sidebar-link">2.2 版本控制思想</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_2-3-版本工具" class="sidebar-link">2.3 版本工具</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_3-1-简介" class="sidebar-link">3.1 简介</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_3-2-git环境的搭建" class="sidebar-link">3.2 Git环境的搭建</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_3-2-1-git的下载" class="sidebar-link">3.2.1 Git的下载</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_3-2-2-git可视化客户端" class="sidebar-link">3.2.2 Git可视化客户端</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-1-初始化仓库" class="sidebar-link">4.1 初始化仓库</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-2-添加文件" class="sidebar-link">4.2 添加文件</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-3-git-流程全景图" class="sidebar-link">4.3 Git 流程全景图</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-4-git工作流程" class="sidebar-link">4.4 Git工作流程</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-5-工作区和暂存区" class="sidebar-link">4.5 工作区和暂存区</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-6-查看文件状态" class="sidebar-link">4.6 查看文件状态</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-7-查看提交日志" class="sidebar-link">4.7 查看提交日志</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-8-查看差异" class="sidebar-link">4.8 查看差异</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-9-版本回退" class="sidebar-link">4.9 版本回退</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-10-管理修改" class="sidebar-link">4.10 管理修改</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-11-修改撤销" class="sidebar-link">4.11 修改撤销</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-12-删除文件" class="sidebar-link">4.12 删除文件</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-13-分支管理" class="sidebar-link">4.13 分支管理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-1-查看分支" class="sidebar-link">4.13.1 查看分支**</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-2-创建分支" class="sidebar-link">4.13.2 创建分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-3-切换分支" class="sidebar-link">4.13.3 切换分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-4-创建-切换分支" class="sidebar-link">4.13.4 创建 + 切换分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-5-合并分支" class="sidebar-link">4.13.5 合并分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_4-13-6-删除分支" class="sidebar-link">4.13.6 删除分支**</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_4-14-文件冲突" class="sidebar-link">4.14 文件冲突</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-1-初始化仓库" class="sidebar-link">5.1 初始化仓库</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-2-添加文件" class="sidebar-link">5.2 添加文件</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-3-查看文件状态" class="sidebar-link">5.3 查看文件状态</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-4-查看提交日志" class="sidebar-link">5.4 查看提交日志</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-5-查看差异" class="sidebar-link">5.5 查看差异</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-6-版本回退" class="sidebar-link">5.6 版本回退</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-7-删除文件" class="sidebar-link">5.7 删除文件</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-8-分支管理" class="sidebar-link">5.8 分支管理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_5-8-1-创建分支" class="sidebar-link">5.8.1 创建分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_5-8-2-切换分支" class="sidebar-link">5.8.2 切换分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_5-8-3-查看分支" class="sidebar-link">5.8.3 查看分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_5-8-4-合并分支" class="sidebar-link">5.8.4 合并分支</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_5-9-文件冲突" class="sidebar-link">5.9 文件冲突</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_6-1-远程仓库介绍" class="sidebar-link">6.1 远程仓库介绍</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_6-2-gitee-码云-的使用" class="sidebar-link">6.2 Gitee（码云）的使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_6-2-1-注册与登录" class="sidebar-link">6.2.1 注册与登录</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_6-2-2-创建项目" class="sidebar-link">6.2.2 创建项目</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_6-3-3-项目初始化" class="sidebar-link">6.3.3 项目初始化</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_6-3-4-添加团队成员" class="sidebar-link">6.3.4 添加团队成员</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_6-3-使用ssh方式操作" class="sidebar-link">6.3 使用SSH方式操作</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-1-配置idea" class="sidebar-link">7.1 配置IDEA</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-2-项目克隆" class="sidebar-link">7.2 项目克隆</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-3-文件状态识别" class="sidebar-link">7.3 文件状态识别</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-4-git操作" class="sidebar-link">7.4 Git操作</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_7-4-1-git-add-添加暂存区" class="sidebar-link">7.4.1 git add--添加暂存区</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_7-4-2-git-commit-提交本地仓库" class="sidebar-link">7.4.2 git commit--提交本地仓库</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_7-4-3-git-push-推送远程仓库" class="sidebar-link">7.4.3 git push--推送远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#_7-4-4-git-pull-更新本地仓库" class="sidebar-link">7.4.4 git pull--更新本地仓库</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-5-完整开发流程" class="sidebar-link">7.5 完整开发流程</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤1-克隆项目" class="sidebar-link">步骤1：克隆项目</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤2-创建自己开发分支" class="sidebar-link">步骤2：创建自己开发分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤3-在自己本地分支编码" class="sidebar-link">步骤3：在自己本地分支编码</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤4-切换到本地master分支" class="sidebar-link">步骤4：切换到本地master分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤5-将自己分支代码合并到master分支" class="sidebar-link">步骤5：将自己分支代码合并到master分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤6-将本地master的分支推送到远程仓库master分支" class="sidebar-link">步骤6：将本地master的分支推送到远程仓库master分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤7-模拟同事合并代码进入远程仓库" class="sidebar-link">步骤7：模拟同事合并代码进入远程仓库</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤8-拉取远程仓库master最新代码到本地master分支" class="sidebar-link">步骤8：拉取远程仓库master最新代码到本地master分支</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤9-切换到自己本地分支-合并master-然后继续开发" class="sidebar-link">步骤9：切换到自己本地分支，合并master，然后继续开发</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤10-来回重复步骤5到步骤9" class="sidebar-link">步骤10：来回重复步骤5到步骤9</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤11-本地自己分支远程备份" class="sidebar-link">步骤11：本地自己分支远程备份</a></li><li class="sidebar-sub-header level3"><a href="/pages/ca48f7/#步骤12-最后的注意" class="sidebar-link">步骤12：最后的注意</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-6-文件冲突" class="sidebar-link">7.6 文件冲突</a></li><li class="sidebar-sub-header level2"><a href="/pages/ca48f7/#_7-7-保命小结" class="sidebar-link">7.7 保命小结</a></li></ul></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E6%8A%80%E6%9C%AF%E5%A2%9E%E5%80%BC" title="分类" data-v-06225672>技术增值</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-03-12</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">Git版本控制<!----></h1>  <div class="theme-vdoing-content content__default"><p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/5cb9f1351759ecc4a052c43cebabf368.jpeg" alt="5cb9f1351759ecc4a052c43cebabf368"></p> <h1 id="一、今日学习内容与目标"><a href="#一、今日学习内容与目标" class="header-anchor">#</a> 一、今日学习内容与目标</h1> <ol><li>掌握git的工作流程</li> <li>熟悉git安装使用</li> <li>掌握git的基本使用</li> <li>掌握分支管理</li> <li>掌握IDEA操作git</li> <li>掌握使用git远程仓库</li> <li>掌握git常用命令</li></ol> <h1 id="二、版本控制"><a href="#二、版本控制" class="header-anchor">#</a> 二、版本控制</h1> <h2 id="_2-1-团队开发问题"><a href="#_2-1-团队开发问题" class="header-anchor">#</a> 2.1 团队开发问题</h2> <p>企业项目一般以团队形式实施开发，那团队开发中会出现哪些问题呢？</p> <ol><li>小明负责的模块就要完成了，就在即将Release之前的一瞬间，电脑突然蓝屏，硬盘光荣牺牲！几个月来的努力付之东流——需求之一：<strong>备份！</strong></li> <li>这个项目中需要一个很复杂的功能，老王摸索了一个星期终于有眉目了，可是这被改得面目全非的代码已经回不到从前了。什么地方能买到哆啦A梦的时光机啊？需求之二：<strong>代码还原！</strong></li> <li>小刚和小强先后从文件服务器上下载了同一个文件：<code>Analysis.java</code>。小刚在<code>Analysis.java</code>文件中的第30行声明了一个方法，叫<code>count()</code>，先保存到了文件服务器上；小强在<code>Analysis.java</code>文件中的第50行声明了一个方法，叫<code>sum()</code>，也随后保存到了文件服务器上，于是，<code>count()</code>方法就只存在于小刚的记忆中了——需求之三：<strong>协同修改！</strong></li> <li>老许是一位项目经理，他需要把每一个版本的项目都保存一份, 而且这些工程里其实有很多文件都是重复的,导致电脑空间经常不足 , 要找某个版本的时候也很麻烦——需求之四：<strong>多版本项目文件管理！</strong></li> <li>老王是另一位项目经理，每次因为项目进度挨骂之后，他都不知道该扣哪个程序员的工资！就拿这次来说吧，有个该死的<code>Bug</code>调试了30多个小时才知道是因为相关属性没有在应用初始化时赋值！可是小强、小明、小刚和小军都不承认是自己干的！——需求之五：<strong>追溯问题代码的编写人和编写时间！</strong></li> <li>小温这两天幸福的如同掉进了蜜罐里，因为他成功的得到了前台MM丽丽的芳心，可他郁闷的是这几天总是收到<code>QA</code>小组的邮件，要求他修正程序中存在的<code>Bug</code>，可他自己本地电脑上是没有这些Bug的，“难道我的代码被哪个孙子给改了？”。是的，小温没来的时候，丽丽是<code>QA</code>小组小郑的女朋友啊！——需求之六：<strong>权限控制！</strong></li></ol> <h2 id="_2-2-版本控制思想"><a href="#_2-2-版本控制思想" class="header-anchor">#</a> 2.2 版本控制思想</h2> <p>要解决上面问题，需要引入新的思想：版本控制思想</p> <p><strong>版本控制:</strong>  版本控制(<code>Revision control</code>)是维护工程蓝图的标准做法，能<strong>追踪工程蓝图从诞生一直到定案的过程</strong>。是一种记录若干文件内容变化过程，以便将来查阅特定版本修订情况的系统。</p> <p>版本控制深入程序员在团队配合中，如果你的项目没有版本控制：
一、 代码管理混乱。
二、 解决代码冲突困难。
三、 在代码整合期间引发BUG。
四、 无法对代码的拥有者进行权限控制。
五、 项目不同版本发布困难。
......</p> <h2 id="_2-3-版本工具"><a href="#_2-3-版本工具" class="header-anchor">#</a> 2.3 版本工具</h2> <p><strong>集中式版本控制（SVN）</strong></p> <p>SVN是集中式版本控制系统，版本库是集中放在中央服务器的，而干活的时候，用的都是自己的电脑，所以首先要从中央服务器哪里得到最新的版本，然后干活，干完后，需要把自己做完的活推送到中央服务器。集中式版本控制系统是必须联网才能工作，如果在局域网还可以，带宽够大，速度够快，如果在互联网下，如果网速慢的话，就郁闷了。</p> <p>下图就是标准的集中式版本控制工具管理方式：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1571728355239.png" alt="1571728355239"></p> <p>集中管理方式在一定程度上看到其他开发人员在干什么，而管理员也可以很轻松掌握每个人的开发权限。</p> <p>但是相较于其优点而言，集中式版本控制工具缺点很明显：</p> <ol><li>服务器单点故障</li> <li>容错性差</li></ol> <p><strong>分布式版本控制（Git）</strong></p> <p>Git是分布式版本控制系统，每个人的电脑就是一个完整的版本库，这样，工作的时候就不需要联网了，因为版本都是在自己的电脑上。然后团队协作再通过远程仓库进行协作。</p> <p>当然，<code>Git</code>的优势不单是不必联网这么简单，后面我们还会看到<code>Git</code>极其强大的<strong>分支管理</strong>，把<code>SVN</code>等远远抛在了后面。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/6_2.png" alt="6_2"></p> <h1 id="三、git简介"><a href="#三、git简介" class="header-anchor">#</a> 三、Git简介</h1> <h2 id="_3-1-简介"><a href="#_3-1-简介" class="header-anchor">#</a> 3.1 简介</h2> <p>很多人都知道，<code>Linus</code>在<strong>1991年创建了开源的Linux</strong>，从此，<code>Linux</code>系统不断发展，已经成为最大的<strong>服务器系统软件</strong>了。</p> <p><code>Linus</code>虽然创建了<code>Linux</code>，但<code>Linux</code>的壮大是靠全世界热心的志愿者参与的，这么多人在世界各地为<code>Linux</code>编写代码，那<code>Linux</code>的代码是如何管理的呢？</p> <p>事实是，在2002年以前，世界各地的志愿者把源代码文件通过 diff 的方式发给<code>Linus</code>，然后由<code>Linus</code>本人通过手工方式合并代码！</p> <p>你也许会想，为什么<code>Linus</code>不把<code>Linux</code>代码放到版本控制系统里呢？不是有<code>CVS</code>、<code>SVN</code>这些免费的版本控制系统吗？因为<code>Linus</code>坚定地反对<code>CVS</code>和<code>SVN</code>，这些集中式的版本控制系统不但速度慢，而且必须联网才能使用。有一些商用的版本控制系统，虽然比<code>CVS</code>、<code>SVN</code>好用，但那是付费的，和<code>Linux</code>的<strong>开源精神</strong>不符。</p> <p>不过，到了2002年，<code>Linux</code>系统已经发展了十年了，代码库之大让<code>Linus</code>很难继续通过手工方式管理了，社区的弟兄们也对这种方式表达了强烈不满，于是<code>Linus</code>选择了一个商业的版本控制系统<code>BitKeeper</code>，<code>BitKeeper</code>的东家<code>BitMover</code>公司出于人道主义精神，授权<code>Linux</code>社区免费使用这个版本控制系统。</p> <p>安定团结的大好局面在2005年就被打破了，原因是<code>Linux</code>社区牛人聚集，不免沾染了一些梁山好汉的江湖习气。开发<code>Samba</code>的<code>Andrew</code>试图破解<code>BitKeeper</code>的协议（这么干的其实也不只他一个），被<code>BitMover</code>公司发现了（监控工作做得不错！），于是<code>BitMover</code>公司怒了，要收回<code>Linux</code>社区的免费使用权。</p> <p><code>Linus</code>可以向<code>BitMover</code>公司道个歉，保证以后严格管教弟兄们，嗯，这是不可能的。实际情况是这样的：</p> <p><code>Linus</code>花了两周时间自己用C写了一个<strong>分布式版本控制系统</strong>，这就是<code>Git</code>！一个月之内，<code>Linux</code>系统的源码已经全部交由<code>Git</code>管理了！牛是怎么定义的呢？大家可以体会一下。</p> <p><code>Git</code>迅速成为最流行的<strong>分布式版本控制系统</strong>，尤其是2008年，<code>GitHub</code>网站上线了，它为开源项目免费提供<code>Git</code>存储，无数开源项目开始迁移至<code>GitHub</code>，包括<code>jQuery</code>，<code>PHP</code>，<code>Ruby</code>等等。</p> <p>历史就是这么偶然，如果不是当年<code>BitMover</code>公司威胁<code>Linux</code>社区，可能现在我们就没有免费而超级好用的<code>Git</code>了。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1571726570657.png" alt="1571726570657"></p> <h2 id="_3-2-git环境的搭建"><a href="#_3-2-git环境的搭建" class="header-anchor">#</a> 3.2 Git环境的搭建</h2> <h3 id="_3-2-1-git的下载"><a href="#_3-2-1-git的下载" class="header-anchor">#</a> 3.2.1 Git的下载</h3> <p>https://git-scm.com/download</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1669814688387.png" alt="1669814688387"></p> <p>我们使用Windows系统，所以安装Windows 版本的git软件。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109154301253.png" alt="image-20230109154301253"></em></p> <p>一路“Next”使用默认选项即可，安装说明详情见 《git安装.docx》安装完成后，可以在任意文件夹点右键，看到如下菜单：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1669814877523.png" alt="1669814877523"></em></p> <h3 id="_3-2-2-git可视化客户端"><a href="#_3-2-2-git可视化客户端" class="header-anchor">#</a> 3.2.2 Git可视化客户端</h3> <p>TortoiseGit是一款开源的Git图形界面工具，使用TortoiseGit可以简化Git相关的操作（本质上还是执行的Git相关命令）。TortoiseGit下载地址： https://tortoisegit.org/download/</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1669814908676.png" alt="1669814908676"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109154603935.png" alt="image-20230109154603935"></em></p> <p>安装说明详情见资料下的《TortoiseGit安装》，基本上也是一路“Next”使用默认选项直到Finish完成。安装完毕后在系统右键菜单中会出现TortoiseGit的菜单项。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1669816041758.png" alt="1669816041758"></em></p> <blockquote><p>扩展操作</p></blockquote> <p>TortoiseGit 客户端可以让git文件图标根据不同状态显示不同效果，安装成功后，重启一下电脑就可以。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109172827799.png" alt="image-20230109172827799"></p> <p>部分win7  win8  win10 系统即使重启，也显示不同，原因是系统图标显示与TortoiseGit 图标显示冲突导致的。</p> <p>修复方式：https://blog.csdn.net/Aaron_King/article/details/126153694</p> <h1 id="四、git-命令操作"><a href="#四、git-命令操作" class="header-anchor">#</a> 四、Git 命令操作</h1> <h2 id="_4-1-初始化仓库"><a href="#_4-1-初始化仓库" class="header-anchor">#</a> 4.1 初始化仓库</h2> <p>Git操作前需要初始化仓库，用于存储版本管理的项目代码，目前仓库有2种类型：</p> <ul><li>本地仓库：是在开发人员自己电脑上的仓库</li> <li>远程仓库：是在远程服务器上的仓库（跟团队其他成员共用）</li></ul> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/14_2.png" alt="14_2"></em></p> <p>配置自己名称与邮箱账户，在公司一般是自己名称拼音与公司邮箱</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> config <span class="token parameter variable">--global</span> user.name <span class="token string">&quot;Your Name&quot;</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> user.email <span class="token string">&quot;email@example.com&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/15.png" alt="15"></em></p> <p>初始化本地仓库</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> init
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/17_2.png" alt="17_2"></em></p> <p>命令执行后，会在当前目录下多了一个<code>.git</code>的目录，这个目录是<code>Git</code>本地仓库，用于跟踪与管理代码(文件)，<strong>没事别手动修改这个目录里面的文件</strong>，容易改乱了，导致<code>Git</code>仓库给蹦了。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/18_2.png" alt="18_2"></em></p> <blockquote><p>这里要注意，部分同学电脑没勾选 隐藏项目 选项，会看不见 .git 目录</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1669817134491.png" alt="1669817134491"></p> <h2 id="_4-2-添加文件"><a href="#_4-2-添加文件" class="header-anchor">#</a> 4.2 添加文件</h2> <p>仓库初始化好了，怎么将文件添加到仓库，并管理起来呢？</p> <p><strong>步骤1：创建一个普通文本文件</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/18_2.png" alt="18_2"></em></p> <p><strong>步骤2：将文件添加到暂存区</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> <span class="token function">add</span> readme.txt
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>步骤3：将文件添加到版本库</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">&quot;添加了readme.txt文件&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/19_2.png" alt="19_2"></em></p> <p>简单解释一下<code>git commit</code>命令，<code>-m</code>后面输入的是本次提交的说明，可以输入任意内容，当然<strong>最好是有意义</strong>的，这样你就能从历史记录里方便地找到改动记录。
<code>git commit</code>命令执行成功后会告诉你，1个文件被改动（我们新添加的readme.txt文件）</p> <blockquote><p>扩展</p></blockquote> <p>如果后续添加文件多了，可以使用下面命令</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> <span class="token function">add</span> file1.txt
<span class="token function">git</span> <span class="token function">add</span> file2.txt file3.txt
<span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>   当前文件夹下所有文件
<span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">&quot;add 3 files.&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="_4-3-git-流程全景图"><a href="#_4-3-git-流程全景图" class="header-anchor">#</a> 4.3 Git 流程全景图</h2> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/1571728415965.png" alt="1571728415965"></p> <h2 id="_4-4-git工作流程"><a href="#_4-4-git工作流程" class="header-anchor">#</a> 4.4 Git工作流程</h2> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20201112093833752.png" alt="image-20201112093833752"></p> <h2 id="_4-5-工作区和暂存区"><a href="#_4-5-工作区和暂存区" class="header-anchor">#</a> 4.5 工作区和暂存区</h2> <p>在Git中进行 crud 操作时都需要执行 git add 文件这个操作，底层操作将操作文件添加一个叫缓存区区域中缓存，当操作完毕之后，使用 git commit 操作，进行统一提交，将编辑文件统一同步版本中</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/33_2.png" alt="33_2"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/34_2.png" alt="34_2"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/35.png" alt="35"></p> <h2 id="_4-6-查看文件状态"><a href="#_4-6-查看文件状态" class="header-anchor">#</a> 4.6 查看文件状态</h2> <p>**问题：**如何查看项目目前的状态？我在电脑前写了一段时间代码，用Git管理，中途上厕所，然后又去吃了个苹果，继续回来工作，不记得之前用Git干了些什么了？</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> status <span class="token comment"># 查看当前git版本库的状态(查看缓存区中的文件内容)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/26_2.png" alt="26_2"></em></p> <h2 id="_4-7-查看提交日志"><a href="#_4-7-查看提交日志" class="header-anchor">#</a> 4.7 查看提交日志</h2> <p>实际工作中，我们脑子里怎么可能记得一个几千行的文件每次都改了什么内容，不然要版本控制系统干什么。版本控制系统肯定有某个命令可以告诉我们<strong>历史记录</strong>，在<code>Git</code>中，我们用<code>git log</code>命令查看</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> log
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/22_2.png" alt="22_2"></em></p> <p><code>git log</code> 命令显示从最近到最远的提交日志，如果嫌输出信息太多，看得眼花缭乱的，可以试试加上<code>--pretty=oneline</code>参数：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> log <span class="token parameter variable">--pretty</span><span class="token operator">=</span>oneline
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/23_2.png" alt="23_2"></em></p> <p>黄色长长的字符串是本次提交的commit id， 是<code>Git</code>使用<code>SHA-1</code>算法产生<strong>唯一标识符，能保证全球唯一</strong>。</p> <h2 id="_4-8-查看差异"><a href="#_4-8-查看差异" class="header-anchor">#</a> 4.8 查看差异</h2> <p>如果一个文件知道被人修改了，但如果能看看具体修改了什么内容，自然是更好的
比如你休假两周从国外回来，第一天上班时，已经记不清上次怎么修改的<code>readme.txt</code>，所以，需要用<code>git diff</code>这个命令看看：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> <span class="token function">diff</span> <span class="token comment"># 查看不同版本之间的文件差异</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/28_2.png" alt="28_2"></em></p> <h2 id="_4-9-版本回退"><a href="#_4-9-版本回退" class="header-anchor">#</a> 4.9 版本回退</h2> <p>我们不断修改文件，不断的往版本库中提交文件。就好比玩<code>RPG</code>游戏时，每通过一关就会自动把游戏状态存盘，如果某一关没过去，你还可以选择读取前一关的状态。有些时候，在打<code>Boss</code>之前，你会手动存盘，以便万一打<code>Boss</code>失败了，可以从最近的地方重新开始。<code>Git</code>也是一样，每当你觉得文件修改到一定程度的时候，就可以**“保存一个快照”**，这个快照在<code>Git</code>中被称为 <code>commit</code>。一旦你把文件改乱了，或者误删了文件，还可以从最近的一个<code>commit</code> 恢复，然后继续工作，而不是把几个月的工作成果全部丢失。</p> <p><strong>如果想回到上一个版本，应该怎么做呢？</strong></p> <p><code>Git</code>必须知道当前版本是哪个版本，在<code>Git</code>中，用<code>HEAD</code>表示当前版本，上一个版本就是<code>HEAD^</code>，上上一个版本就是<code>HEAD^^</code>，当然往上100个版本写100个^比较容易数不过来，所以写成<code>HEAD~100</code>。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> reset <span class="token parameter variable">--hard</span> HEAD^
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/30_2.png" alt="30_2"></em></p> <p><strong>回到指定版本</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> reset <span class="token parameter variable">--hard</span> <span class="token operator">&lt;</span>commit id<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/31_2.png" alt="31_2"></em></p> <p>拓展需求: 如何回退到最新版本</p> <h2 id="_4-10-管理修改"><a href="#_4-10-管理修改" class="header-anchor">#</a> 4.10 管理修改</h2> <p>使用Git修改文件，存在一个需要探讨的问题：二次修改</p> <p><strong>操作方式1:</strong> <code>第一次修改 -&gt; git add -&gt; 第二次修改 -&gt; git commit</code></p> <p><strong>操作方式2：推荐使用</strong> <code>第一次修改 -&gt; git add -&gt; 第二次修改 -&gt; git add -&gt; git commit</code></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109163751783.png" alt="image-20230109163751783"></p> <p><strong>注意：建议在每次 commit 之前先检查是否有文件没有被 add</strong></p> <h2 id="_4-11-修改撤销"><a href="#_4-11-修改撤销" class="header-anchor">#</a> 4.11 修改撤销</h2> <p>git checkout -- filename`可以丢弃工作区的修改：<strong>-- 后面是一个空格</strong></p> <p>命令 <code>git checkout -- readme.txt</code> 意思就是，把 <code>readme.txt</code> 文件在工作区的修改全部撤销，这里有两种情况：
一：<code>readme.txt</code> 自修改后还没有被放到暂存区(<code>git add</code>)，现在，撤销修改就回到和版本库一模一样的状态；
二：<code>readme.txt</code> 已经添加到暂存区后，又作了修改，现在，撤销修改就回到添加到暂存区后的状态。</p> <p>总之，就是让这个文件回到最近一次 <code>git commit</code> 或 <code>git add</code> 时的状态。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109163834344.png" alt="image-20230109163834344"></p> <p><strong>注意:</strong> <code>git checkout -- file</code> 命令中的 <code>--</code> 很重要，没有 <code>--</code> ，就变成了**“切换到另一个分支”**的命令，我们在后面的分支管理中会再次遇到 <code>git checkout</code> 命令</p> <h2 id="_4-12-删除文件"><a href="#_4-12-删除文件" class="header-anchor">#</a> 4.12 删除文件</h2> <p>一般情况下，你通常直接在文件管理器中把没用的文件删了，或者用<code>rm</code>命令删了：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> <span class="token function">rm</span> test.txt
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这个时候，<code>Git</code>知道你删除了文件，因此，工作区和版本库就不一致了，<code>git status</code>命令会立刻告诉你哪些文件被删除了：</p> <p>删除完成后需要 <code>commit</code></p> <p>如果删除了想恢复,可以使用 <code>reset</code> 版本恢复</p> <p>步骤1：本地删除没用的文件（查看状态）</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/42_2.png" alt="42_2"></em></p> <p>步骤2：先 add 以下（查看状态与步骤1进行比较）</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/41_2.png" alt="41_2"></em></p> <p>步骤3：提交删除文件</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/43_2.png" alt="43_2"></em></p> <h2 id="_4-13-分支管理"><a href="#_4-13-分支管理" class="header-anchor">#</a> 4.13 分支管理</h2> <p>分支管理的是Git灵魂，开发必不可少基本操作，必须掌握。</p> <p>为啥存在分支？因为项目成品经过这几个流程： 开发， 测试，上线，bug修改，多版本发布等。同一个项目不同版本同时开发，同时测试，同时上线，怎么确保在这种复杂情况下让项目能独立，又能相关关联执行下去呢？Git给出解决方案是<strong>分支管理</strong>， 每一个阶段就是一个分支，即可以相互独立，又可以相互合并。</p> <h3 id="_4-13-1-查看分支"><a href="#_4-13-1-查看分支" class="header-anchor">#</a> 4.13.1 查看分支**</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> branch
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/45_2.png" alt=""></em></p> <h3 id="_4-13-2-创建分支"><a href="#_4-13-2-创建分支" class="header-anchor">#</a> <strong>4.13.2 创建分支</strong></h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> branch <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/46_2.png" alt=""></em></p> <h3 id="_4-13-3-切换分支"><a href="#_4-13-3-切换分支" class="header-anchor">#</a> <strong>4.13.3 切换分支</strong></h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> checkout <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_4-13-4-创建-切换分支"><a href="#_4-13-4-创建-切换分支" class="header-anchor">#</a> <strong>4.13.4 创建 + 切换分支</strong></h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> checkout <span class="token parameter variable">-b</span> <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_4-13-5-合并分支"><a href="#_4-13-5-合并分支" class="header-anchor">#</a> 4.13.5 合并分支</h3> <p><strong>将某分支合并到当前分支</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> merge <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/47_2.png" alt="47_2"></em></p> <h3 id="_4-13-6-删除分支"><a href="#_4-13-6-删除分支" class="header-anchor">#</a> 4.13.6 删除分支**</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> branch <span class="token parameter variable">-d</span> <span class="token operator">&lt;</span>name<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>项目分支使用简化版</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/62_2.png" alt="62_2"></p> <p><strong>项目分支使用完整版</strong></p> <p><strong>master分支</strong>：用于版本的更新，当比较大的功能开发完成或者更新之后会有一次集体的发版，就会将所有的代码都合到master（有的公司也会用release分支发版，原理都是一样）；</p> <p><strong>develop分支</strong>：一般是开发测试分支，在项目发版上线之前都会现在dev分支上统一进行测试，确保功能达标没有bug之后再推到master分支；</p> <p><strong>feature分支</strong>：用来做分模块功能开发，建议命名为feature-xxx,模块完成之后，会合并到 dev 分支；</p> <p><strong>hotfix/fixbug分支</strong>：是用来做线上的紧急 bug 修复的分支,建议命名为 hotfix-xxx。当线上某个版本出现了问题，将检出对应版本的代码，创建 Hotfix 分支，问题修复后，合并回 dev和master  ，这里注意，合并到 master 的时候，一般要打上修复后的版本标签。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/Git.jpg" alt=""></p> <p><strong>扩展阅读：https://blog.csdn.net/langfeiyes/article/details/126068779</strong></p> <h2 id="_4-14-文件冲突"><a href="#_4-14-文件冲突" class="header-anchor">#</a> 4.14 文件冲突</h2> <p>分支1中有个文件跟其他分支文件一样，如果同时发生修改了，进行合并，就出现文件冲突问题。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/49_2.png" alt="49_2"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/50_2.png" alt="50_2"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/51_2.png" alt="51_2"></em></p> <h1 id="五、git可视化操作"><a href="#五、git可视化操作" class="header-anchor">#</a> 五、Git可视化操作</h1> <p>上面使用bash命令操作， 接下来，使用TortoiseGit可视化工具再操作一遍Git命令。</p> <h2 id="_5-1-初始化仓库"><a href="#_5-1-初始化仓库" class="header-anchor">#</a> 5.1 初始化仓库</h2> <p><strong>设置用户名与邮箱</strong></p> <p>创建空白目录，右键</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109170938773.png" alt="image-20230109170938773"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171142037.png" alt="image-20230109171142037"></p> <p><strong>初始化仓库</strong></p> <p>空白目录，右键</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171255360.png" alt="image-20230109171255360"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171435524.png" alt="image-20230109171435524"></em></p> <h2 id="_5-2-添加文件"><a href="#_5-2-添加文件" class="header-anchor">#</a> 5.2 添加文件</h2> <p>新建readme.txt文件，执行 add 操作</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171635223.png" alt="image-20230109171635223"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171800128.png" alt="image-20230109171800128"></em></p> <p><strong>接着执行commit</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109171952795.png" alt="image-20230109171952795"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109172129536.png" alt="image-20230109172129536"></em></p> <p>操作成功</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109172232261.png" alt="image-20230109172232261"></em></p> <h2 id="_5-3-查看文件状态"><a href="#_5-3-查看文件状态" class="header-anchor">#</a> 5.3 查看文件状态</h2> <p>修改一下readme.txt文件, 借助图标观察变化</p> <p>修改未提交：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109173437956.png" alt="image-20230109173437956"></em></p> <p>修改已提交：</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109173656278.png" alt="image-20230109173656278"></em></p> <h2 id="_5-4-查看提交日志"><a href="#_5-4-查看提交日志" class="header-anchor">#</a> 5.4 查看提交日志</h2> <p>选中文件</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109173756023.png" alt="image-20230109173756023"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109173915524.png" alt="image-20230109173915524"></em></p> <h2 id="_5-5-查看差异"><a href="#_5-5-查看差异" class="header-anchor">#</a> 5.5 查看差异</h2> <p>再修改readme.txt文件，添加：hello git</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174037550.png" alt="image-20230109174037550"></em></p> <p>查看与版本的差异</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174205027.png" alt="image-20230109174205027"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174257376.png" alt="image-20230109174257376"></p> <h2 id="_5-6-版本回退"><a href="#_5-6-版本回退" class="header-anchor">#</a> 5.6 版本回退</h2> <p>保存并提交readme.txt改动的数据，此时先回退到没有保存前的版本。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174434619.png" alt="image-20230109174434619"></em></p> <p>使用show log 查看版本日志</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174521900.png" alt="image-20230109174521900"></em></p> <p>现在想回退到，<strong>“修改readme.txt”</strong> 版本</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109174945926.png" alt="image-20230109174945926"></em></p> <p>选择硬回退</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175043993.png" alt="image-20230109175043993"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175128483.png" alt="image-20230109175128483"></em></p> <p>操作完之后，master分支版本就回到上一个版本， show log是看不到当前版本之后日志，只能通过 show reflog才行</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175343294.png" alt="image-20230109175343294"></em></p> <h2 id="_5-7-删除文件"><a href="#_5-7-删除文件" class="header-anchor">#</a> 5.7 删除文件</h2> <p>删除有2种模式，一种删除版本库，留下工作区的，一个是全删除</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175539111.png" alt="image-20230109175539111"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175606855.png" alt="image-20230109175606855"></em></p> <p>工作区删除成功之后，必须提交一次，保证版本库中文件同步删除</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175736117.png" alt="image-20230109175736117"></em></p> <h2 id="_5-8-分支管理"><a href="#_5-8-分支管理" class="header-anchor">#</a> 5.8 分支管理</h2> <p>创建test.txt文件， 并提交，方便分支创建观察效果。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109175938008.png" alt="image-20230109175938008"></em></p> <h3 id="_5-8-1-创建分支"><a href="#_5-8-1-创建分支" class="header-anchor">#</a> 5.8.1 创建分支</h3> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109180032831.png" alt="image-20230109180032831"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109180117461.png" alt="image-20230109180117461"></em></p> <h3 id="_5-8-2-切换分支"><a href="#_5-8-2-切换分支" class="header-anchor">#</a> 5.8.2 切换分支</h3> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109180307767.png" alt="image-20230109180307767"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109180352272.png" alt="image-20230109180352272"></em></p> <h3 id="_5-8-3-查看分支"><a href="#_5-8-3-查看分支" class="header-anchor">#</a> 5.8.3 查看分支</h3> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109180933221.png" alt="image-20230109180933221"></p> <h3 id="_5-8-4-合并分支"><a href="#_5-8-4-合并分支" class="header-anchor">#</a> 5.8.4 合并分支</h3> <p>切换到dev分支并创建dev.txt文件，执行add 跟 commit 命令，注意合并前必须提交，保证工作区与版本库一致，否则会出现莫名其妙的问题。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181227973.png" alt="image-20230109181227973"></em></p> <p><strong>需求： 将dev分支的dev.txt文件合并到master分支中</strong></p> <p><strong>步骤1：切换到master分支，此时master分支没有dev.txt文件</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181345408.png" alt="image-20230109181345408"></em></p> <p><strong>步骤2：在master分支执行合并</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181439600.png" alt="image-20230109181439600"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181652042.png" alt="image-20230109181652042"></em></p> <p><strong>步骤3：合并成功</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181714970.png" alt="image-20230109181714970"></em></p> <h2 id="_5-9-文件冲突"><a href="#_5-9-文件冲突" class="header-anchor">#</a> 5.9 文件冲突</h2> <p><strong>步骤1：在master分支修改dev.txt文件，注意： 先修改， 在add， 最后commit， 保证跟版本库一致</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109181906755.png" alt="image-20230109181906755"></em></p> <p><strong>步骤2：切换到dev分支修改dev.txt文件，注意： 先修改， 在add， 最后commit， 保证跟版本库一致</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182059896.png" alt="image-20230109182059896"></em></p> <p><strong>步骤3：切换到master分支，将dev分支改动后数据合并到master分支中</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182251345.png" alt="image-20230109182251345"></em></p> <p>合并冲突了</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182338018.png" alt="image-20230109182338018"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182420121.png" alt="image-20230109182420121"></em></p> <p><strong>步骤4：解决冲突</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182533429.png" alt="image-20230109182533429"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182659319.png" alt="image-20230109182659319"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182825698.png" alt="image-20230109182825698"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109182930990.png" alt="image-20230109182930990"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109183032398.png" alt="image-20230109183032398"></em></p> <h1 id="六、远程仓库"><a href="#六、远程仓库" class="header-anchor">#</a> 六、远程仓库</h1> <h2 id="_6-1-远程仓库介绍"><a href="#_6-1-远程仓库介绍" class="header-anchor">#</a> 6.1 远程仓库介绍</h2> <p>到目前为止，我们已经学会了如何在本机利用git进行文件版本管理，但是如果要想进行多人协作，我们就必须使用远程仓库。将本地仓库的数据同步到远程仓库，实现多人协作开发。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230113150901318.png" alt="image-20230113150901318"></p> <p>一般我们有可能接触到比较多的几种 Git 远程仓库平台：</p> <p>​	<a href="https://github.com/" target="_blank" rel="noopener noreferrer">GitHub<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>：国外/免费创建公有仓库/私有仓库需要收费，在国际上来说 GitHub 是最活跃的开源社区</p> <p>​	<a href="https://gitlab.com/" target="_blank" rel="noopener noreferrer">GitLab<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>：国外/国内免费创建公有仓库/私有仓库需要收费，不过 GitLab 提供了开源版本的企业版本，企业可以部署一套 GitLab 的私服在自己的服务器中</p> <p>​	<a href="https://gitee.com/" target="_blank" rel="noopener noreferrer">Gitee<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>：国内/免费创建公有|私有仓库/私有仓库限制成员不得超过5人</p> <h2 id="_6-2-gitee-码云-的使用"><a href="#_6-2-gitee-码云-的使用" class="header-anchor">#</a> 6.2 Gitee（码云）的使用</h2> <p>GitHub<code>虽然好，在国外的使用率也很高，但毕竟是国外的。在网速上效率还是比较低，经常会出现访问页面变得很慢，下载项目很慢的情况，于是国内慢慢发展起了一个类似</code>GitHub<code>的</code>Git` 开源平台 <a href="https://gitee.com" target="_blank" rel="noopener noreferrer">Gitee<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>。官网：https://gitee.com/</p> <h3 id="_6-2-1-注册与登录"><a href="#_6-2-1-注册与登录" class="header-anchor">#</a> 6.2.1 注册与登录</h3> <p>要使用 Gitee，首先还是需要创建一个账户，有账户后，直接登录，进入主页</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109183958053.png" alt="image-20230109183958053"></p> <h3 id="_6-2-2-创建项目"><a href="#_6-2-2-创建项目" class="header-anchor">#</a> 6.2.2 创建项目</h3> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109184142640.png" alt="image-20230109184142640"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109184353646.png" alt="image-20230109184353646"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109184450965.png" alt="image-20230109184450965"></p> <h3 id="_6-3-3-项目初始化"><a href="#_6-3-3-项目初始化" class="header-anchor">#</a> 6.3.3 项目初始化</h3> <p>项目初始化就是在本地搭建好项目基本功能(比如脚手架)，现在需要将该项目推送到远程仓库， 保证团队能共享该项目，这个过程就是项目初始化。简单理解：将本地项目丢到远程仓库</p> <p><strong>步骤1：初始化git本地仓库</strong></p> <p>首先进入到你需要进行初始化的项目根目录，并按照如下步骤进行操作：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> config <span class="token parameter variable">--global</span> user.name <span class="token string">&quot;码云上的名称&quot;</span>
<span class="token function">git</span> config <span class="token parameter variable">--global</span> user.email <span class="token string">&quot;码云上面注册邮箱&quot;</span>
<span class="token function">git</span> init
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>步骤2：设置提交忽略文件</strong></p> <p>在项目根目录下创建文件： .gitignore</p> <p>这一步的意义是为了避免项目中有些本地环境特有的文件被传入到远程仓库，这些文件每个人的电脑都有可能不一致，如果提交到远程仓库，可能会导致出现频繁冲突的问题</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code># <span class="token class-name">Created</span> by <span class="token punctuation">.</span>ignore support plugin <span class="token punctuation">(</span>hsz<span class="token punctuation">.</span>mobi<span class="token punctuation">)</span>

# <span class="token class-name">Operating</span> <span class="token class-name">System</span> <span class="token class-name">Files</span>

<span class="token operator">*</span><span class="token punctuation">.</span>DS_Store
<span class="token class-name">Thumbs</span><span class="token punctuation">.</span>db
<span class="token operator">*</span><span class="token punctuation">.</span>sw<span class="token operator">?</span>
<span class="token punctuation">.</span>#<span class="token operator">*</span>
<span class="token operator">*</span>#
<span class="token operator">*</span><span class="token operator">~</span>
<span class="token operator">*</span><span class="token punctuation">.</span>sublime<span class="token operator">-</span><span class="token operator">*</span>

# <span class="token class-name">Build</span> <span class="token class-name">Artifacts</span>

<span class="token punctuation">.</span>gradle<span class="token operator">/</span>
build<span class="token operator">/</span>
target<span class="token operator">/</span>
bin<span class="token operator">/</span>
dependency<span class="token operator">-</span>reduced<span class="token operator">-</span>pom<span class="token punctuation">.</span>xml

# <span class="token class-name">Eclipse</span> <span class="token class-name">Project</span> <span class="token class-name">Files</span>

<span class="token punctuation">.</span>classpath
<span class="token punctuation">.</span>project
<span class="token punctuation">.</span>settings<span class="token operator">/</span>

# <span class="token class-name">IntelliJ</span> <span class="token constant">IDEA</span> <span class="token class-name">Files</span>

<span class="token operator">*</span><span class="token punctuation">.</span>iml
<span class="token operator">*</span><span class="token punctuation">.</span>ipr
<span class="token operator">*</span><span class="token punctuation">.</span>iws
<span class="token operator">*</span><span class="token punctuation">.</span>idea
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109185647884.png" alt="image-20230109185647884"></em></p> <p><strong>步骤3：本地仓库初始化</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span>  <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token function">git</span>  commit <span class="token parameter variable">-m</span> “项目初始化”
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>步骤4：配置远程仓库路径(注意是自己建仓库路径)</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> remote <span class="token function">add</span> origin 你在马云上创建的仓库地址<span class="token punctuation">(</span>注意https/ssh方式区别<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>步骤5：将本地仓库项目推送到远程仓库</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">git</span> push <span class="token parameter variable">-u</span> origin master
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>步骤6：查看推送结果</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109185525571.png" alt="image-20230109185525571"></p> <p><strong>重点注意点：存在一部分人https方式无法正常提交，可以参考扩展视频： SSH方式如何进行项目初始化</strong></p> <h3 id="_6-3-4-添加团队成员"><a href="#_6-3-4-添加团队成员" class="header-anchor">#</a> 6.3.4 添加团队成员</h3> <p>创建好项目以后，就可以添加团队成员了，公司的项目通常都是私有仓库，大部分公司会利用类似 Gitlab 的开源平台搭建公司专属的 Git 远程仓库，其配置也基本都差不多，即进入项目管理/设置页面，找到成员管理并邀请成员，为其设置权限等等操作即可</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109185752134.png" alt="image-20230109185752134"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109185830851.png" alt="image-20230109185830851"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109185903338.png" alt="image-20230109185903338"></p> <h2 id="_6-3-使用ssh方式操作"><a href="#_6-3-使用ssh方式操作" class="header-anchor">#</a> 6.3 使用SSH方式操作</h2> <p>进入账号设置页面</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230612151040939.png" alt="image-20230612151040939"></em></p> <p>左边选择</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230612151259397.png" alt="image-20230612151259397"></em></p> <p>点击生成公钥</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230612151323100.png" alt="image-20230612151323100"></p> <p>按照操作步骤生成公钥</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230612151400069.png" alt="image-20230612151400069"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/165113_8e58f0e1_551147-59f6a70c273a338dad20e5cb8945ac5e.webp" alt="输入图片说明"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/165455_ec7dbd09_551147-afec57da5858ea02dae4935c382c4264.webp" alt="输入图片说明"></p> <p>复制生成后的 ssh key，通过仓库主页 「账号设置」-&gt;「SSH公钥」 ，添加生成的 public key 添加到仓库中。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230612151607535.png" alt="image-20230612151607535"></p> <h1 id="七、idea中操作git"><a href="#七、idea中操作git" class="header-anchor">#</a> 七、IDEA中操作Git</h1> <h2 id="_7-1-配置idea"><a href="#_7-1-配置idea" class="header-anchor">#</a> 7.1 配置IDEA</h2> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110133114974.png" alt="image-20230110133114974"></p> <h2 id="_7-2-项目克隆"><a href="#_7-2-项目克隆" class="header-anchor">#</a> 7.2 项目克隆</h2> <p>通常来说，进入公司以后会发给你一个远程 Git 仓库的账号密码，以及仓库地址，当你得到仓库地址后，即可在开发工具当中将该仓库下载到本地</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230109190206741.png" alt="image-20230109190206741"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110133312386.png" alt="image-20230110133312386"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110133449843.png" alt="image-20230110133449843"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110134123702.png" alt="image-20230110134123702"></em></p> <p><strong>注意：在微服务开发或者按模块开发的情况下，因为一个仓库下可能包含多个项目文件，因此建议使用命令 git clone 先将远程仓库克隆到本地，然后再将仓库中的项目一个个导入到 idea</strong></p> <h2 id="_7-3-文件状态识别"><a href="#_7-3-文件状态识别" class="header-anchor">#</a> 7.3 文件状态识别</h2> <p>在 idea 中，使用不同的颜色来标识文件的不同状态。</p> <p>通常情况下，有这样几种颜色：</p> <p>​	**棕色：**色代表未被 Git 管理（未添加到暂存区）</p> <p>​	**绿色：**代表新增的文件且已经被加入到暂存区了</p> <p>​	**蓝色：**代表该文件已经提交到远程且该文件被编辑过了</p> <p>​	**黑色：**代表该文件在当前版本与远程是一致的</p> <p>​	**灰色：**表示该文件之前被提交到仓库过（不管是远程还是本地），但是他已经被删除了</p> <p>​	**红色：**表示该文件的内容出现了冲突</p> <p>创建新文件时，idea 会弹出一个提示框，确认是否要添加到 git 暂存区</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110134724158.png" alt="image-20230110134724158"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135247326.png" alt="image-20230110135247326"></em></p> <h2 id="_7-4-git操作"><a href="#_7-4-git操作" class="header-anchor">#</a> 7.4 Git操作</h2> <h3 id="_7-4-1-git-add-添加暂存区"><a href="#_7-4-1-git-add-添加暂存区" class="header-anchor">#</a> 7.4.1 git add--添加暂存区</h3> <p><strong>方式一</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135435723.png" alt="image-20230110135435723"></p> <p><strong>方式二</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135525200.png" alt="image-20230110135525200"></p> <h3 id="_7-4-2-git-commit-提交本地仓库"><a href="#_7-4-2-git-commit-提交本地仓库" class="header-anchor">#</a> 7.4.2 git commit--提交本地仓库</h3> <p>本地提交</p> <p><strong>方式一</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135730394.png" alt="image-20230110135730394"></p> <p><strong>方式二</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135804261.png" alt="image-20230110135804261"></p> <p><strong>方式三</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110135837434.png" alt="image-20230110135837434"></p> <p><strong>点击提交之后</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140035944.png" alt="image-20230110140035944"></p> <h3 id="_7-4-3-git-push-推送远程仓库"><a href="#_7-4-3-git-push-推送远程仓库" class="header-anchor">#</a> 7.4.3 git push--推送远程仓库</h3> <p><strong>远程推送</strong></p> <p><strong>方式一</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140325724.png" alt="image-20230110140325724"></p> <p><strong>方式二</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140406845.png" alt="image-20230110140406845"></p> <h3 id="_7-4-4-git-pull-更新本地仓库"><a href="#_7-4-4-git-pull-更新本地仓库" class="header-anchor">#</a> 7.4.4 git pull--更新本地仓库</h3> <p><strong>方式一</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140656695.png" alt="image-20230110140656695"></p> <p><strong>方式二</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140620388.png" alt="image-20230110140620388"></p> <p><strong>方式三</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110140735725.png" alt="image-20230110140735725"></p> <h2 id="_7-5-完整开发流程"><a href="#_7-5-完整开发流程" class="header-anchor">#</a> 7.5 完整开发流程</h2> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110141034419.png" alt="image-20230110141034419"></p> <h3 id="步骤1-克隆项目"><a href="#步骤1-克隆项目" class="header-anchor">#</a> 步骤1：克隆项目</h3> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110133312386.png" alt="image-20230110133312386"></p> <h3 id="步骤2-创建自己开发分支"><a href="#步骤2-创建自己开发分支" class="header-anchor">#</a> 步骤2：创建自己开发分支</h3> <p>团队开发中有约定， 不能在master分支进行代码编写， 包括自己本地分支，所以开发时需要拉出自己开发分支。</p> <p>在idea右下角，创建</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110184933000.png" alt="image-20230110184933000"></p> <p>创建成功之后，会默认切换到新建的分支。</p> <h3 id="步骤3-在自己本地分支编码"><a href="#步骤3-在自己本地分支编码" class="header-anchor">#</a> 步骤3：在自己本地分支编码</h3> <p>一个需求开发，一般都是自己拉一条分支， 在这个分支中实现自己负责的需求。当开发完成部分独立需求(比如实现某个完整逻辑)，可以自己单元测试， 测试通过之后，git add   git commit 提交本地自己分支。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110185636782.png" alt="image-20230110185636782"></em></p> <p><strong>这里要注意，必须将自己分支代码，commit之后才能执行步骤4</strong></p> <h3 id="步骤4-切换到本地master分支"><a href="#步骤4-切换到本地master分支" class="header-anchor">#</a> 步骤4：切换到本地master分支</h3> <p>在自己本地分支开发完之后， 测试无bug之后， 保证已经commit之后，切换到master分支</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110185953475.png" alt="image-20230110185953475"></em></p> <h3 id="步骤5-将自己分支代码合并到master分支"><a href="#步骤5-将自己分支代码合并到master分支" class="header-anchor">#</a> 步骤5：将自己分支代码合并到master分支</h3> <p>当自己分支代码ok之后，合并到master分支</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110190923460.png" alt="image-20230110190923460"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110191009771.png" alt="image-20230110191009771"></em></p> <h3 id="步骤6-将本地master的分支推送到远程仓库master分支"><a href="#步骤6-将本地master的分支推送到远程仓库master分支" class="header-anchor">#</a> 步骤6：将本地master的分支推送到远程仓库master分支</h3> <p>注意：自己分支合并到master分支后，需要对自己代码进行测试，测试ok后，如果改动了代码，需要再次commit，然后推送到远程仓库的master分支中。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110191241683.png" alt="image-20230110191241683"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110191421719.png" alt="image-20230110191421719"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110191537127.png" alt="image-20230110191537127"></em></p> <h3 id="步骤7-模拟同事合并代码进入远程仓库"><a href="#步骤7-模拟同事合并代码进入远程仓库" class="header-anchor">#</a> 步骤7：模拟同事合并代码进入远程仓库</h3> <p>公司项目以团队形式进行，你提交的代码，你同事一样提交代码，使用码云仓库控制台模拟同事合并代码进入远程仓库。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110191852394.png" alt="image-20230110191852394"></p> <p><strong>编写类名</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110192141610.png" alt="image-20230110192141610"></p> <p><strong>写好备注</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110192229542.png" alt="image-20230110192229542"></p> <p><strong>添加成功</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110192255997.png" alt="image-20230110192255997"></em></p> <h3 id="步骤8-拉取远程仓库master最新代码到本地master分支"><a href="#步骤8-拉取远程仓库master最新代码到本地master分支" class="header-anchor">#</a> 步骤8：拉取远程仓库master最新代码到本地master分支</h3> <p>远程仓库代码已经更新，新一天编码开始前，先拉取远程仓库最新代码。注意，最新代码在远程master分支，拉取最新代码应该切换到本地的master分支，然后再执行git pull命令。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110192707663.png" alt="image-20230110192707663"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110193625563.png" alt="image-20230110193625563"></em></p> <h3 id="步骤9-切换到自己本地分支-合并master-然后继续开发"><a href="#步骤9-切换到自己本地分支-合并master-然后继续开发" class="header-anchor">#</a> 步骤9：切换到自己本地分支，合并master，然后继续开发</h3> <p>还是那句，开发只能在自己分支中进行， 步骤8中本地master已经拉取到最新代码，马上切换到自己本地分支，将最新代码合并进来，继续开发。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194200279.png" alt="image-20230110194200279"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194227424.png" alt="image-20230110194227424"></em></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194315692.png" alt="image-20230110194315692"></em></p> <h3 id="步骤10-来回重复步骤5到步骤9"><a href="#步骤10-来回重复步骤5到步骤9" class="header-anchor">#</a> 步骤10：来回重复步骤5到步骤9</h3> <p>后续开发就是步骤5到步骤9的重复啦。</p> <h3 id="步骤11-本地自己分支远程备份"><a href="#步骤11-本地自己分支远程备份" class="header-anchor">#</a> 步骤11：本地自己分支远程备份</h3> <p>除了可以将本地master分支推送到远程master分支外，本地自己分支也可以推送一份到远程仓库自己的分支。</p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194626374.png" alt="image-20230110194626374"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194814933.png" alt="image-20230110194814933"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194905038.png" alt="image-20230110194905038"></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110194938662.png" alt="image-20230110194938662"></em></p> <p>自己本地分支推送到远程分支好处：</p> <p>1&gt;<strong>备份</strong></p> <p>2&gt;天选打工人， 公司没干完活，回家从远程仓库下代码继续开发。</p> <h3 id="步骤12-最后的注意"><a href="#步骤12-最后的注意" class="header-anchor">#</a> 步骤12：最后的注意</h3> <p>为了操作简便性，上课使用master分支存放日常开发成员提交的代码，真实开发不能这么玩，master分支一般存放的都是一些要发布的，或者已经发布的项目版本，不是这些没有经过正规专业测试开发代码。</p> <p><strong>真实开发使用develop先来存放日常开发代码。所以，到公司之后，必须问清楚开发分支是哪一条。</strong></p> <p><strong>上面步骤1到步骤11，将master改成develop就可以啦</strong></p> <h2 id="_7-6-文件冲突"><a href="#_7-6-文件冲突" class="header-anchor">#</a> 7.6 文件冲突</h2> <p>Git 文件冲突在2种情况下回出现</p> <p>1&gt;本地分支间相互合并</p> <p>2&gt;本地分支与远程分支相互合并</p> <p>这里演示一下第二种情况。</p> <p><strong>步骤1：在本地master分支，A.java文件写上下面代码， 然后add， 并commit</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200049644.png" alt="image-20230110200049644"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200228708.png" alt="image-20230110200228708"></p> <p><strong>步骤2：切换到码云控制台，在远程master分支，改动A.java文件，模拟同事同时修改了该文件</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200341206.png" alt="image-20230110200341206"></p> <p>修改文件</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200427728.png" alt="image-20230110200427728"></p> <p><strong>步骤3：切换到idea，将本地master分支push到远程分支</strong></p> <p><em><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200603814.png" alt="image-20230110200603814"></em></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110200845080.png" alt="image-20230110200845080"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110201025679.png" alt="image-20230110201025679"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110201104295.png" alt="image-20230110201104295"></p> <p><strong>解决完冲突之后，再一次push ，将最新代码合并入远程master分支。</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110201205530.png" alt="image-20230110201205530"></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/image-20230110201256234.png" alt="image-20230110201256234"></p> <h2 id="_7-7-保命小结"><a href="#_7-7-保命小结" class="header-anchor">#</a> 7.7 保命小结</h2> <p>1&gt;在公司必须清楚每条分支线是干嘛的， 不清楚就问</p> <p>2&gt;每次合并分支，特别是push pull 最好进行代码硬备份，等于买了复活甲。</p> <p>3&gt;学习期间放手操作，把问题消灭在学习阶段。</p> <h1 id="八、小结与作业"><a href="#八、小结与作业" class="header-anchor">#</a> 八、小结与作业</h1> <ul><li>Git命令实践</li> <li>Git可视化操作</li> <li>Git远程仓库使用</li> <li>Gitee码云使用</li> <li>Gitee Idea中使用</li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=Git" title="标签">#Git</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/9e54ff/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Activiti7工作流讲义</div></a> <!----></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/9e54ff/" class="prev">Activiti7工作流讲义</a></span> <!----></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/68.868cd00b.js" defer></script>
  </body>
</html>
